package zjitc.web.servlet;

import zjitc.domain.Test;
import zjitc.service.UserService;
import zjitc.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/findUserServlet")
public class FindUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1. 获取name
        String name = request.getParameter("name");
        //2. 调用service查询
        UserService service = new UserServiceImpl();
        Test user = service.findUserByName(name);
        //3. 将user存入request域
        request.setAttribute("user",user);
        //4. 转发到update.jsp
        request.getRequestDispatcher("/update.jsp").forward(request,response);


    }
}
